<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.liangjie.bbs.Article"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="com.liangjie.bbs.DB"%>
<%@page import="java.sql.Connection"%>
<%@page pageEncoding="utf-8"%>

<%
	request.setCharacterEncoding("utf-8");
	String action = request.getParameter("action");

	if (action != null && action.trim().equals("post")) {
		String title = request.getParameter("title");
		String cont = request.getParameter("cont");

		/*
		out.println(title);
		out.println(cont);
		 */
		int rootId = 0;

		//将传入的内容输入数据库
		Connection conn = DB.getConn();
		boolean autoCommit = conn.getAutoCommit();
		conn.setAutoCommit(false);

		PreparedStatement pStmt = DB
				.getPreStmt(
						conn,
						"insert into article values (null, 0, ?, ?, ?, now(), 0)",
						Statement.RETURN_GENERATED_KEYS);
		pStmt.setInt(1, rootId);
		pStmt.setString(2, title);
		pStmt.setString(3, cont);
		pStmt.executeUpdate();

		//拿到自动生成的id号
		ResultSet autoGeneratedKeys = pStmt.getGeneratedKeys();
		autoGeneratedKeys.next();
		rootId = autoGeneratedKeys.getInt(1);

		Statement stmt = DB.getStmt(conn);
		stmt.executeUpdate("update article set rootid = " + rootId
				+ " where id = " + rootId);

		conn.commit();
		conn.setAutoCommit(autoCommit);

		DB.close(autoGeneratedKeys);
		DB.close(stmt);
		DB.close(pStmt);
		DB.close(conn);
		/*String from = request.getParameter("from");
		System.out.println(from);
		if (from.equals("tree")) {
			response.sendRedirect("./article.jsp");
		} else if (from.equals("flat")) {
			response.sendRedirect("./articleflat.jsp");
		}*/
		response.sendRedirect("./articleflat.jsp");
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<!-- ckeditor -->
<script src="./ckeditor/ckeditor.js"></script>
<link rel="stylesheet" href="./ckeditor/samples/sample.css" />
<!-- ckeditor -->

<title>发表新主题</title>

<link rel="stylesheet" type="text/css"
	href="./sources/article_detail/style_5_common.css" />
<link rel="stylesheet" type="text/css"
	href="./sources/article_detail/style_5_forum_viewthread.css" />

<style type="text/css"></style>

<link rel="archives" title="花粉俱乐部"
	href="http://cn.club.vmall.com/archiver/" />
<link
	href="http://static.huafans.cn/template/hw_fans/image/zh//favicon.ico"
	rel="shortcut icon" />
<link rel="stylesheet" type="text/css"
	href="./sources/article_detail/huafans_national_com.css" />
<link rel="stylesheet" type="text/css"
	href="./sources/article_detail/huafans_national.css" />

<link href="./sources/article_detail/bdsstyle.css" rel="stylesheet"
	type="text/css" />

<style type="text/css">
body {
	margin: 0;
	width: auto;
}
</style>

</head>
<body id="nv_forum" class="pg_viewthread"
	onkeydown="if(event.keyCode==27) return false;">

	<div id="append_parent"></div>
	<div id="ajaxwaitid"></div>
	<div id="toptb" class="cl">
		<div class="topbar-bg">
			<div class="wp"></div>
		</div>
	</div>

	<div id="wp" class="wp">

		<!--[diy=diynavtop]-->
		<div id="diynavtop" class="area"></div>
		<!--[/diy]-->
		<div class="wp">
			<!--[diy=diy1]-->
			<div id="diy1" class="area"></div>
			<!--[/diy]-->
		</div>
		<div id="ct" class="wp ct2 cl">
			<div class="mn">
				<div id="postlist" class="pl bm">
					<table cellspacing="0" cellpadding="0">
						<tbody>
							<tr>
								<td class="plc ptm pbn vwthd">
									<h1 class="ts">
										<a href="">[发表]</a> <span id="thread_subject">新主题帖</span>
									</h1> <span class="xg1"> &nbsp;<img
										src="./sources/article_detail/hot_3.gif" alt=""
										title="热度: 1723" /> <a onclick="alert('功能尚未开放，感谢您的关注！')">[复制帖子标题和链接]</a>
								</span>
									<p class="pdh-misc"></p>
								</td>
							</tr>

						</tbody>

					</table>

					<!--[TODO]分割线 [begin] -->
					<table cellspacing="0" cellpadding="0" class="ad">
						<tbody>
							<tr>
								<td class="pls"></td>
							</tr>
						</tbody>
					</table>
					<!--[TODO]分割线 [end] -->

					<div>
						<form action="./post.jsp" method="post">

							<!-- 输入框 -->
							<input type="hidden" name="action" value="post" /> <br />标题：<input
								type="text" name="title" size="80" /> <br /> <br />正文：
							<textarea class="ckeditor" name="cont" rows="5" cols="100"></textarea>
							<br /> <br />
							<!-- 输入框 -->

							<!--[TODO]分割线 [begin] -->
							<table cellspacing="0" cellpadding="0" class="ad">
								<tbody>
									<tr>
										<td class="pls"></td>
									</tr>
								</tbody>
							</table>
							<!--[TODO]分割线 [end] -->

							<!-- 发表回复按钮 -->
							<div class="hbp-pager" style="padding:10px 20px;">
								<input type="submit" class="mkbtn-blue newpost"
									id="newspecialtmp" value="发表回复" /> <br /> <br />
							</div>
							<!-- 发表回复按钮 -->

						</form>
					</div>
				</div>
			</div>
		</div>


		<div id="ft" class="wp cl">
			<div id="flk" class="wp mk-box">
				<p>Copyright © 2011-2013 华为软件技术有限公司 版权所有 保留一切权利</p>
			</div>
		</div>
	</div>
</body>
</html>